package com.ruoyi.Processor;

import com.ruoyi.common.entity.Project;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

// 标题处理器
class TitleProcessor implements ContentProcessor {
    @Override
    public boolean canProcess(Element element) {
        return element.tagName().matches("h[1-6]");
    }
    
    @Override
    public void process(Element element, Project project) {
        String text = element.text().trim();
        
        // 根据标题内容判断应该设置哪个字段
        if (text.contains("项目介绍")) {
            project.setIntroTitle(text);
        } else if (text.contains("课程目录")) {
            project.setCatalogTitle(text);
        } else if (project.getContentTitle() == null) {
            project.setContentTitle(text);
        }
        
        // 检查标题中是否包含图片
        Elements images = element.select("img");
        if (!images.isEmpty()) {
            String src = images.first().attr("src");
            if (project.getResourceUrl() == null) {
                project.setResourceUrl(src);
            }
        }
    }
}